package ui;

import obj.BossEnemy;
import obj.Enemy;
import obj.ShootingEnemy;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;

import play.Things;

import util.Settings;

/**
 * Gives the user an indication when the game has ended.
 * @author VincentLy
 */
public class GameOver extends BasicGameState{

	private CustomButton back;	
	private String s1 = "Game Over.";
	private float ex,ey = -1;

	public GameOver(){
		super();
		back = new CustomButton(Settings.screenX/2-Settings.buttonX/2,Settings.screenY-Settings.buttonY*2,"Return to Main Menu",'b');
	}

	/**
	 * Initialization not needed yet.
	 * @author VincentLy
	 */
	public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {}

	/**
	 * Resets the game as needed.
	 * @author VincentLy
	 */
	public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
		Input i = gc.getInput();
		ex = i.getMouseX();
		ey = i.getMouseY();
		if(back.contains(ex,ey)){
			back.setOn(true);
			Settings.retry = true;
			Things.newenemies.clear();
			for(Enemy e: Things.enemies){
				if(e instanceof BossEnemy)
					((BossEnemy) e).clean();
				else if(e instanceof ShootingEnemy){
					((ShootingEnemy) e).clean();
				}
			}
			Things.enemies.clear();
			Things.projectiles.clear();
			Things.platforms.clear();
			Things.player.stop();
			Things.player.setHP(500);
			Things.player.setHit(false);
			Things.x = 300;
			Things.y = 300;
			Things.warps = 0;
			Things.file = "res/world1platforms.txt";
			if(i.isMousePressed(Input.MOUSE_LEFT_BUTTON))	
				sbg.enterState(Settings.smID);	
		}	
		else
			back.setOn(false);
	}

	/**
	 * Draws the game over screen.
	 * @author VincentLy
	 */
	public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
		g.setAntiAlias(true);
		g.setBackground(Settings.bg);
		Settings.gameover.draw(185,-50);
		g.setColor(Settings.screenText);
		g.drawString(s1,(Settings.screenX-g.getFont().getWidth(s1))/2,g.getFont().getHeight(s1));
		back.draw(g);
	}

	/**
	 * @return id
	 * @author VincentLy
	 */
	public int getID() {return Settings.goID;}
}